package com.smarttiger.zero.admin.dao;

import com.smarttiger.zero.admin.dto.InterfaceLogicDto;
import com.smarttiger.zero.admin.entity.InterfaceLogicModel;
import com.smarttiger.zero.admin.entity.LogicModel;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface InterfaceLogicDao extends BaseDao<InterfaceLogicModel> {

    public List<InterfaceLogicModel> findAllByInterfaceId(String id);

    @Query("select new com.smarttiger.zero.admin.dto.InterfaceLogicDto( il.id,il.interfaceId,il.logicId,il.sort,l.name) " +
            "from InterfaceLogicModel il inner join LogicModel l on il.logicId = l.id " +
            "where il.interfaceId = ?1")
    public List<InterfaceLogicDto> findAllByInterfaceId2(String id);

    @Modifying
    @Query("delete from InterfaceLogicModel es where es.interfaceId = ?1 ")
    public void deleteByInterfaceId(String id);


    @Query("select u from LogicModel u inner join InterfaceLogicModel bl on u.id = bl.logicId " +
            "where bl.interfaceId = ?1 order by bl.sort ")
    public List<LogicModel> queryLogicModelByInterfaceId(String interfaceId);



}
